# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: net_requests_auth.py 
@time: 2019/7/10 下午2:03
"""
'''
 通过requests进行用户登陆以及cookies传递
'''
import requests

# 设置URL
url='https://pypi.org/account/login/'
#设置参数
params = {
    'username': 'nzj1981',
    'password': 'nzj3971215',
    'csrf_token':'4wDSTLkb07KOrn19HlEzOY-tz8Nj06UvcRPROs0vBxQ'
}
# 设置头信息
headers = {
    'Host': 'pypi.org',
    'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0',
    'Referer': 'https://pypi.org/account/login/',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Accept-Encoding': 'gzip, deflate, br',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Connection': 'keep-alive',
    'Cookie': '_ga=GA1.2.1298907835.1562740991; _gid=GA1.2.1499016644.1562740991; session_id=DSrNUIBf29_D09YRL795knOdCim0hkp_m42PXGBp80c.XSWVKw.0xhPGSadIESta2Ry6Th-05b8jL7Qd0vwuaglUiYGzmwWRwWdxkbmr3wNzw4zw3Mjqx9nUaHL5dx4K6XsC4LCHA; XDEBUG_SESSION=PHPSTORM',
    'Upgrade-Insecure-Requests': '1'
}
resp = requests.post(url,params=params,headers=headers)

print(resp.status_code)
print(resp.text)
print('此代码用户登陆不成功')